package org.farec.tcc.spring.controller;

import java.sql.Connection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.farec.tcc.dao.EmailDAO;
import org.farec.tcc.dao.PermissaoDAO;
import org.farec.tcc.dao.UsuarioDAO;
import org.farec.tcc.modelo.Email;
import org.farec.tcc.modelo.Permissao;
import org.farec.tcc.modelo.Usuario;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

public class EmpresaController {
	
	
	@RequestMapping("/exibeEmpresa")
	public String mostra(int id, Model model, HttpServletRequest request) 
	{
		Connection connection = (Connection) request.getAttribute("conexao");

		HttpSession session = request.getSession();
		Usuario usuario = (Usuario) session.getAttribute("usuarioLogado");
		PermissaoDAO daoPermissao = new PermissaoDAO(connection);
		List<Permissao> permissaoList = daoPermissao.verificaPermissao(usuario,"item");
		
		for(Permissao p : permissaoList)
		{
			if(p.getModulo().equals("Empresa") && p.getItem().equals("alterar"))
			{
				//Falta fazer os metodos
			}
		}
		
		return "editempresa";
		
	}
	
	@RequestMapping("/alterarEmpresa")
	public String altera(Email email, HttpServletRequest request)
	{
		Connection connection = (Connection) request.getAttribute("conexao");
		
		HttpSession session = request.getSession();
		Usuario usuario = (Usuario) session.getAttribute("usuarioLogado");
		PermissaoDAO daoPermissao = new PermissaoDAO(connection);
		UsuarioDAO daoUsuario = new UsuarioDAO(connection);
		int codEmpresa = daoUsuario.verificaEmpresa(usuario);
		List<Permissao> permissaoList = daoPermissao.verificaPermissao(codEmpresa,usuario,"item");
		
		for(Permissao p : permissaoList)
		{
			if(p.getModulo().equals("Empresa") && p.getItem().equals("alterar"))
			{
				//Alterar os dados cadastrais
			}
		}

		return "index";
	}
	
	

}
